import { EChartsOption } from 'echarts';
import { graphic } from 'echarts/core';

// 工作动态图表配置
export const workTrendOpt: EChartsOption = {
    backgroundColor: '#fff',
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'shadow'
        }
    },
    legend: {
        data: ['党政工作', '教学活动', '学生活动', '国际交流'],
        textStyle: {
            color: '#333'
        }
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: {
        type: 'category',
        data: ['8月', '9月', '10月', '11月', '12月', '1月'],
        axisLine: {
            lineStyle: {
                color: '#1a6840'
            }
        }
    },
    yAxis: {
        type: 'value',
        axisLine: {
            show: true,
            lineStyle: {
                color: '#1a6840'
            }
        }
    },
    series: [
        {
            name: '党政工作',
            type: 'bar',
            data: [12, 15, 18, 14, 10, 8],
            itemStyle: {
                color: '#1a6840'
            }
        },
        {
            name: '教学活动',
            type: 'bar',
            data: [20, 25, 30, 28, 22, 15],
            itemStyle: {
                color: '#4c8c2b'
            }
        },
        {
            name: '学生活动',
            type: 'bar',
            data: [15, 18, 25, 22, 18, 12],
            itemStyle: {
                color: '#f8b62d'
            }
        },
        {
            name: '国际交流',
            type: 'bar',
            data: [5, 8, 12, 10, 8, 5],
            itemStyle: {
                color: '#8b5a2b'
            }
        }
    ]
};

// 学科分布图表配置
export const subjectDistOpt: EChartsOption = {
    backgroundColor: '#fff',
    tooltip: {
        trigger: 'item'
    },
    legend: {
        orient: 'vertical',
        right: 10,
        top: 'center',
        textStyle: {
            color: '#333'
        }
    },
    series: [
        {
            name: '学科分布',
            type: 'pie',
            radius: ['40%', '70%'],
            avoidLabelOverlap: false,
            itemStyle: {
                borderRadius: 10,
                borderColor: '#fff',
                borderWidth: 2
            },
            label: {
                show: false,
                position: 'center'
            },
            emphasis: {
                label: {
                    show: true,
                    fontSize: '18',
                    fontWeight: 'bold'
                }
            },
            labelLine: {
                show: false
            },
            data: [
                { value: 35, name: '农学', itemStyle: { color: '#1a6840' } },
                { value: 25, name: '工学', itemStyle: { color: '#4c8c2b' } },
                { value: 20, name: '理学', itemStyle: { color: '#f8b62d' } },
                { value: 15, name: '管理学', itemStyle: { color: '#8b5a2b' } },
                { value: 5, name: '其他', itemStyle: { color: '#d9b382' } }
            ]
        }
    ]
};

// 校园风光图表配置
export const campusViewOpt: EChartsOption = {
    backgroundColor: '#fff',
    tooltip: {
        trigger: 'item',
        formatter: '{a} <br/>{b}: {c} ({d}%)'
    },
    visualMap: {
        show: false,
        min: 0,
        max: 100,
        inRange: {
            colorLightness: [0.8, 0.3]
        }
    },
    series: [
        {
            name: '校园风光',
            type: 'pie',
            radius: '55%',
            center: ['50%', '50%'],
            data: [
                { value: 35, name: '紫荆花海', itemStyle: { color: '#ff6b81' } },
                { value: 25, name: '红满堂', itemStyle: { color: '#ff4757' } },
                { value: 20, name: '行政楼', itemStyle: { color: '#1a6840' } },
                { value: 15, name: '图书馆', itemStyle: { color: '#4c8c2b' } },
                { value: 5, name: '实验基地', itemStyle: { color: '#f8b62d' } }
            ].sort(function (a, b) {
                return a.value - b.value;
            }),
            roseType: 'radius',
            label: {
                color: '#333'
            },
            labelLine: {
                lineStyle: {
                    color: 'rgba(0, 0, 0, 0.3)'
                },
                smooth: 0.2,
                length: 10,
                length2: 20
            },
            itemStyle: {
                borderRadius: 5
            },
            animationType: 'scale',
            animationEasing: 'elasticOut',
            animationDelay: function (idx) {
                return Math.random() * 200;
            }
        }
    ]
};

// 基础柱状图配置
export const barOptions: EChartsOption = {
    xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
    },
    yAxis: {
        type: 'value',
    },
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'shadow',
        },
    },
    color: ['#009688', '#f44336'],
    series: [
        {
            data: [120, 200, 150, 80, 70, 110, 130],
            type: 'bar',
        },
        {
            data: [180, 230, 190, 120, 110, 230, 235],
            type: 'bar',
        },
    ],
};

// 基础折线图配置
export const lineOptions: EChartsOption = {
    tooltip: {
        trigger: 'axis',
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true,
    },
    xAxis: {
        type: 'category',
        boundaryGap: false,
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
    },
    yAxis: {
        type: 'value',
    },
    color: ['#009688', '#f44336'],
    series: [
        {
            name: 'Email',
            type: 'line',
            stack: 'Total',
            areaStyle: {},
            smooth: true,
            data: [120, 132, 101, 134, 90, 230, 210],
        },
        {
            name: 'Union Ads',
            type: 'line',
            stack: 'Total',
            areaStyle: {},
            smooth: true,
            data: [220, 182, 191, 234, 290, 330, 310],
        },
    ],
};

// 基础饼图配置
export const pieOptions: EChartsOption = {
    title: {
        text: 'Referer of a Website',
        subtext: 'Fake Data',
        left: 'center',
    },
    tooltip: {
        trigger: 'item',
    },
    legend: {
        orient: 'vertical',
        left: 'left',
    },
    series: [
        {
            name: 'Access From',
            type: 'pie',
            radius: '50%',
            data: [
                { value: 1048, name: 'Search Engine' },
                { value: 735, name: 'Direct' },
                { value: 580, name: 'Email' },
                { value: 484, name: 'Union Ads' },
                { value: 300, name: 'Video Ads' },
            ],
            emphasis: {
                itemStyle: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)',
                },
            },
        },
    ],
};

// 词云图配置
export const wordOptions: EChartsOption = {
    series: [
        {
            type: 'wordCloud',
            rotationRange: [0, 0],
            autoSize: {
                enable: true,
                minSize: 14,
            },
            textStyle: {
                fontFamily: '微软雅黑,sans-serif',
                color: function () {
                    return (
                        'rgb(' +
                        [
                            Math.round(Math.random() * 160),
                            Math.round(Math.random() * 160),
                            Math.round(Math.random() * 160),
                        ].join(',') +
                        ')'
                    );
                },
            },
            data: [
                {
                    name: '农学',
                    value: 10000,
                },
                {
                    name: '园艺',
                    value: 9000,
                },
                {
                    name: '植物保护',
                    value: 4000,
                },
                {
                    name: '动物科学',
                    value: 7000,
                },
                {
                    name: '兽医',
                    value: 2000,
                },
                {
                    name: '食品科学',
                    value: 6000,
                },
                {
                    name: '工程学院',
                    value: 5000,
                },
                {
                    name: '资源环境',
                    value: 4000,
                },
                {
                    name: '生命科学',
                    value: 3000,
                },
                {
                    name: '经济管理',
                    value: 8000,
                },
                {
                    name: '人文社科',
                    value: 6000,
                },
                {
                    name: '艺术学院',
                    value: 4000,
                },
            ],
        },
    ],
};

// 环形图配置
export const ringOptions: EChartsOption = {
    tooltip: {
        trigger: 'item',
    },
    legend: {
        top: '5%',
        left: 'center',
    },
    series: [
        {
            name: 'Access From',
            type: 'pie',
            radius: ['40%', '70%'],
            avoidLabelOverlap: false,
            itemStyle: {
                borderRadius: 10,
                borderColor: '#fff',
                borderWidth: 2,
            },
            label: {
                show: false,
                position: 'center',
            },
            emphasis: {
                label: {
                    show: true,
                    fontSize: 40,
                    fontWeight: 'bold',
                },
            },
            labelLine: {
                show: false,
            },
            data: [
                { value: 1048, name: '本科生' },
                { value: 735, name: '研究生' },
                { value: 580, name: '博士生' },
                { value: 484, name: '留学生' },
                { value: 300, name: '继续教育' },
            ],
        },
    ],
};

// 仪表盘折线图配置
export const dashOpt1: EChartsOption = {
    xAxis: {
        type: 'category',
        boundaryGap: false,
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
    },
    yAxis: {
        type: 'value',
    },
    grid: {
        top: '2%',
        left: '2%',
        right: '3%',
        bottom: '2%',
        containLabel: true,
    },
    color: ['#009688', '#f44336'],
    series: [
        {
            type: 'line',
            areaStyle: {
                color: new graphic.LinearGradient(0, 0, 0, 1, [
                    {
                        offset: 0,
                        color: 'rgba(0, 150, 136,0.8)',
                    },
                    {
                        offset: 1,
                        color: 'rgba(0, 150, 136,0.2)',
                    },
                ]),
            },
            smooth: true,
            data: [120, 132, 301, 134, 90, 230, 210],
        },
        {
            type: 'line',
            smooth: true,
            data: [220, 122, 191, 234, 190, 130, 310],
        },
    ],
};

// 仪表盘饼图配置
export const dashOpt2: EChartsOption = {
    legend: {
        bottom: '1%',
        left: 'center',
    },
    color: ['#3f51b5', '#009688', '#f44336', '#00bcd4', '#1ABC9C'],
    series: [
        {
            type: 'pie',
            radius: ['40%', '70%'],
            avoidLabelOverlap: false,
            itemStyle: {
                borderRadius: 10,
                borderColor: '#fff',
                borderWidth: 2,
            },
            data: [
                { value: 1048, name: '农学类' },
                { value: 735, name: '工学类' },
                { value: 580, name: '理学类' },
                { value: 484, name: '管理类' },
                { value: 300, name: '艺术类' },
            ],
        },
    ],
};

// 地图配置
export const mapOptions: EChartsOption = {
    tooltip: {
        trigger: 'item',
    },
    geo: {
        map: 'china',
        roam: false,
        emphasis: {
            label: {
                show: false,
            },
        },
    },
    visualMap: {
        show: false,
        min: 0,
        max: 100,
        realtime: false,
        calculable: false,
        inRange: {
            color: ['#d2e0f5', '#71A9FF'],
        },
    },
    series: [
        {
            geoIndex: 0,
            name: '校友分布',
            type: 'map',
            coordinateSystem: 'geo',
            map: 'china',
            data: [
                { name: '北京', value: 100 },
                { name: '上海', value: 100 },
                { name: '广东', value: 100 },
                { name: '浙江', value: 90 },
                { name: '江西', value: 80 },
                { name: '山东', value: 70 },
                { name: '广西', value: 60 },
                { name: '河南', value: 50 },
                { name: '湖北', value: 40 },
                { name: '青海', value: 70 },
                { name: '湖南', value: 30 },
                { name: '黑龙江', value: 20 },
                { name: '新疆', value: 20 },
                { name: '云南', value: 20 },
                { name: '甘肃', value: 20 },
            ],
        },
    ],
};

// 定义图表数据项接口
interface PieChartDataItem {
    value: number;
    name: string;
    itemStyle?: {
        color?: string;
    };
}

// 导出所有配置
export default {
    workTrendOpt,
    subjectDistOpt,
    campusViewOpt,
    barOptions,
    lineOptions,
    pieOptions,
    wordOptions,
    ringOptions,
    dashOpt1,
    dashOpt2,
    mapOptions
};